﻿@using AC.Service.DTO.Blog
@using AC.Util
@model wychuan2.com.Areas.admin.Models.Blog.BlogModel
@{
    ViewBag.Title = "发布随笔";
    Layout = "../Shared/_Layout.cshtml";
}

@{
    string strCategories =  JsonHelper.ToJson(Model.Categories);
    string strTags = JsonHelper.ToJson(Model.Tags);
    
    var lstFirsts = Model.Categories.Where(c => c.ParentId == 0).ToList();
    var lstSeconds = new List<BlogCategoryDTO>();
    if (Model.FirstCategoryId > 0)
    {
        lstSeconds = Model.Categories.Where(c => c.ParentId == Model.FirstCategoryId).ToList();
    }
    else if (lstFirsts.Count > 0)
    {
        lstSeconds = Model.Categories.Where(c => c.ParentId == lstFirsts.First().Id).ToList();
    }
}

@section styles{
    
    <link href="~/Content/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Content/plugins/chosen/chosen.css" rel="stylesheet" />
    <link href="~/Content/plugins/webuploader/webuploader.css" rel="stylesheet" />
}

<input type="hidden" id="preHtmlResult"/>
<div class="row">
    <div class="col-md-12">
        <div class="ibox">
            <div class="ibox-title">
                <h3>随笔发布</h3>
            </div>
            <div class="ibox-content" id="blogContainer">
                <ul class="nav nav-tabs" role="tablist" id="taglist">
                    <li class="active"><a href="#tab1" data-toggle="tab">基础信息</a></li>
                    <li><a href="#tab2" data-toggle="tab">段落</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active m-t-md" id="tab1">
                        <form class="form-horizontal">
                            <input id="hidId" type="hidden" value="@(Model.CurrentBlogs==null?0:Model.CurrentBlogs.Id)" />
                            <div class="form-group">
                                <label class="control-label col-sm-1">Id</label>
                                <div class="col-sm-11">
                                    <input type="text" name="txtBlogId" value="@(Model.CurrentBlogs==null?string.Empty:Model.CurrentBlogs.BlogId)" class="form-control" placeholder="请输入随笔Id" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-1">标题</label>
                                <div class="col-sm-11">
                                    <input type="text" name="txtTitle" value="@(Model.CurrentBlogs==null?string.Empty:Model.CurrentBlogs.Title)" class="form-control" placeholder="请输入随笔标题" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-1">封面</label>
                                <div class="col-sm-11">
                                    <div id="uploader-demo">
                                        <!--用来存放item-->
                                        <div id="fileList" class="uploader-list"></div>
                                        <div id="filePicker">选择图片</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-1">摘要</label>
                                <div class="col-sm-11">
                                    <textarea name="txtSummary" class="form-control"  rows="3" placeholder="请输入随笔摘要">@(Model.CurrentBlogs == null ? string.Empty : Model.CurrentBlogs.Summary)</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-1 col-sm-11">
                                    <label class="checkbox-inline i-checks">
                                        <input name="chkIsPublic" type="checkbox" checked="@(Model.IsPublic?"checked":"")" class="form-control">  公开
                                    </label>
                                </div>
                            </div>

                            <hr />
                            <div class="form-group">
                                <label class="control-label col-sm-1">分类</label>
                                <div class="col-sm-11">
                                    <div class="input-group">
                                        <select class="form-control" name="selFirstCategory">
                                            @foreach (var first in lstFirsts)
                                            {
                                                <option @(Model.FirstCategoryId == first.Id ? "selected" : "") value="@first.Id">@first.Name</option>
                                            }
                                        </select>
                                        <span class="input-group-addon">-</span>
                                        <select class="form-control" name="selSecondCategory">
                                            @foreach (var second in lstSeconds)
                                            {
                                                <option @(Model.CategoryId == second.Id ? "selected" : "") value="@second.Id">@second.Name</option>
                                            }
                                        </select>
                                    </div>
                                    <a href="/admin/blog/setting">管理分类</a>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-1">标签</label>

                                <div class="col-sm-9">
                                    <input type="text" id="txtTags" name="txtTags" value="@Model.TagText" class="form-control" placeholder="输入tab标签，多个之间用,号分隔，最多5个" />
                                    <a href="#modalTags" data-toggle="modal" class="">插入已有标签</a><span class="help-block m-b-none text-info">tab标签，多个之间用,号分隔，最多5个</span>
                                </div>
                            </div>
                            <hr />
                            <div class="text-center">
                                <button type="button" id="btnSave" class="btn btn-primary btn-lg">保存</button>
                                <button type="button" id="btnPreview" class="btn btn-white btn-lg">预览</button>
                            </div>
                        </form>
                    </div>
                    <div class="tab-pane m-t-md" id="tab2">
                        <div class="row m-b-sm m-t-sm" id="sectionSearchContainer">
                            <div class="col-lg-12">
                                <div class="col-lg-4">
                                    <div class="input-group">
                                        <select class="form-control" name="selFirstCategoryQ">
                                            <option value="">一级类目</option>
                                            @foreach (var first in lstFirsts)
                                            {
                                                <option value="@first.Id">@first.Name</option>
                                            }
                                        </select>
                                        <span class="input-group-addon">-</span>
                                        <select class="form-control" name="selSecondCategoryQ">
                                            <option value="">二级类目</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <input id="txtSectionIdQ" type="text" class="form-control" placeholder="sectionId模糊查询" />
                                </div>
                                <div class="col-lg-4">
                                    <div class="input-group">
                                        <select id="selTagsQ" data-placeholder="所有Tag" class="chosen-select" multiple>
                                            <option value="">请选择Tag</option>
                                            @foreach (var tag in Model.Tags)
                                            {
                                                <option value="@tag.Id" hassubinfo="true">@tag.TagName</option>
                                            }
                                        </select>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <button id="btnSearchSections" class="btn btn-primary" type="button">查询</button>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="ibox">
                                    <div class="ibox-content">
                                        <h3>已选随笔段落</h3>
                                        <form class="form-horizontal">
                                            <div class="form-group">
                                                <button id="btnSaveBlogSections" class="btn btn-primary btn-block" type="button">保存随笔段落</button>
                                            </div>
                                        </form>
                                        <hr />
                                        <ul id="sectionsCheckedContainer" class="sortable-list connectList agile-list ui-sortable">
                                            @if (Model.CurrentBlogs != null && Model.CurrentBlogs.BlogSections != null)
                                            {
                                                @Html.Partial("_BlogSectionList", Model.CurrentBlogs.BlogSections)
                                            }
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="col-lg-6">
                                <div class="ibox">
                                    <div class="ibox-content">
                                        <h3>可选随笔段落</h3>
                                        <p class="small"><i class="fa fa-hand-o-up"></i> 拖拽下面段落到左侧列表</p>
                                        @*<form class="form-horizontal">
                                            <div class="form-group">
                                                <label class="control-label col-sm-2">SectionId</label>
                                                <div class="col-sm-10">
                                                    <input id="txtSectionIdQ" type="text" class="form-control" placeholder="输入sectionId查询" />
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">Tags</label>
                                                <div class="col-sm-10">
                                                    <div class="input-group">
                                                        <select id="selTagsQ" data-placeholder="所有Tag" class="chosen-select" multiple>
                                                            <option value="">请选择Tag</option>
                                                            @foreach (var tag in Model.Tags)
                                                            {
                                                                <option value="@tag.Id" hassubinfo="true">@tag.TagName</option>
                                                            }
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="col-sm-offset-2 col-sm-10">
                                                    <button id="btnSearchSections" class="btn btn-primary" type="button">查询</button>
                                                </div>
                                            </div>
                                        </form>*@
                                        <hr />
                                        <ul id="sectionsUnCheckedContainer" class="sortable-list connectList agile-list ui-sortable">
                                            @Html.Partial("_BlogSectionList", Model.SectionsUnChecked)
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
   
            </div>
        </div>
    </div>
</div>


<div id="modalTags" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="lblTags">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="lblTags">选择标签</h4>
            </div>
            <div class="modal-body">
                <div class="alert alert-danger alert-dismissable">
                    <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                    单击选择一个标签，再次单击取消选择.
                </div>
                @foreach (var tag in Model.Tags)
                {
                    <button type="button" name="btnTags" tag-id="@tag.Id" class="btn btn-outline btn-default">@tag.TagName</button>
                }
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="btnSaveTags" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>
</div>

@section scripts{
    @*<script type="text/javascript" src="~/Scripts/plugins/webuploader/webuploader.min.js"></script>*@
    <script src="~/Scripts/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Scripts/plugins/chosen/chosen.jquery.js"></script>
    <script src="~/Scripts/extension.js"></script>
    <script src="~/Scripts/mvcParamMatch.js"></script>

    <style type="text/css">
        .note-editor.fullscreen {
            position: fixed;
            top: 0;
            left: 0;
            z-index: 1029;
            width: 100%;
        }
    </style>
    <script type="text/javascript">
        window.categories = @Html.Raw(strCategories);
        window.tags = @Html.Raw(strTags);
    </script>
    <script type="text/javascript" src="~/Scripts/blog/myblog.js"></script>
}